package com.cabinet.common.filter;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.extension.Activate;
import com.alibaba.dubbo.rpc.Filter;
import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Result;
import com.alibaba.dubbo.rpc.RpcException;


/**
 * dubbo服务过滤器
 * @author lvzf
 *
 */
@Activate(group = Constants.PROVIDER)
public class ShoppingServiceFilter  implements Filter {
	private Log logger = LogFactory.getLog(ShoppingServiceFilter.class);
	@Override
	public Result invoke(Invoker<?> invoker, Invocation invocation)
			throws RpcException {
		Result result =null;
		try {
			//RpcContext context = RpcContext.getContext();
			//MDC.put("serial", logSerial);
		    result = invoker.invoke(invocation);
			Throwable exception = result.getException();
			if (exception != null) {
					logger.warn("系统发生异常：" + exception.getMessage());
					//TODO 记录日志		
			}	
		} catch (Throwable e) {
			logger.error(e.getMessage(), e);
		}
		return result;
	}

}
